from color_setup import ssd  # Create a display instance

import cmath
import math
import utime
import uos
from gui.core.writer import Writer, CWriter
from gui.core.fplot import PolarGraph, PolarCurve, CartesianGraph, Curve, TSequence
from gui.core.nanogui import refresh
from gui.widgets.label import Label

refresh(ssd, True)

# Fonts
import gui.fonts.arial10 as arial10
import gui.fonts.freesans20 as freesans20
from gui.core.colors import *

CWriter.set_textpos(ssd, 0, 0)  # In case previous tests have altered it
wri = CWriter(ssd, arial10, GREEN, BLACK, verbose=False)
wri.set_clip(True, True, False)

def cart(c=lambda x : x+ 2,a=-10,b=10,step=1,xd=10,yd=10,xorigin=10,yorigin=10,bx=-10,by=10):
#     bx by边界
#     xorign yorign 远点处于位置
# [a,b]取值范围 step 取点的步长
# xd yd 格数 width height 分辨率
    print('Cartesian data test.')
    def populate(func):
        x = a
        while x<=b:
            yield x, func(x)  # x, y
            x += step
    refresh(ssd, True)  # Clear any prior image
    g = CartesianGraph(wri, 0, 0, width=200,height=200,xdivs=xd,ydivs=yd,yorigin=yorigin,xorigin=xorigin, fgcolor=WHITE, gridcolor=LIGHTGREEN) 
    curve1 = Curve(g, YELLOW, populate(c),excursion=(bx/-1, by/1)) # args demo
    refresh(ssd)
    return g
cart()
